package com.nineclock.system.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.system.dto.SysSalaryDTO;
import com.nineclock.system.service.SysSalaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/organization")
@Api(value = "员工薪资接口", tags = "系统服务")
public class SysSalaryController {

    @Autowired
    private SysSalaryService salaryService;

    /**
     * 查询员工薪资
     * @return
     */
    @ApiOperation("查询员工薪资")
    @GetMapping("salary/list")
    public Result<List<SysSalaryDTO>> queryCompanyUserSalary(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer pageSize){
        PageResult<SysSalaryDTO> sysSalaryDTOPageResult = salaryService.queryCompanyUserSalary(page,pageSize);
        return Result.success(sysSalaryDTOPageResult.getRows());
    }


/*    @ApiOperation("查询员工薪资")
    @PutMapping("updateSalary")
    public Result updateSalaryByCompanyUserId(@RequestBody SysSalaryDTO sysSalaryDTO){
        salaryService.updateSalaryByCompanyUserId(sysSalaryDTO);
        return Result.success();
    }*/
    @ApiOperation("查询员工薪资")
    @PutMapping("updateSalary/{companyUserId}/{salary}")
    public Result updateSalaryByCompanyUserId(@PathVariable("companyUserId")Long companyUserId,@PathVariable("salary")Long salary){
        SysSalaryDTO sysSalaryDTO = new SysSalaryDTO();
        sysSalaryDTO.setCompanyUserId(companyUserId);
        sysSalaryDTO.setSalary(new BigDecimal(salary.toString()));
        salaryService.updateSalaryByCompanyUserId(sysSalaryDTO);
        return Result.success();
    }
}
